Dart Future operator ==
Syntax & Examples


Future.operator == operator

The equality operator checks if the current Future object is equal to another Future object.


Syntax of Future.operator ==

The syntax of Future.operator == operator is:

operator ==(dynamic other) → bool

This operator == operator of Future the equality operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe Future object to compare with the current Future object for equality.


✐ Example

1 Equality check for Future objects with same values

In this example,

  1. We create two Future objects future1 and future2, both containing the value 42.
  2. We use the equality operator == to check if future1 is equal to future2.
  3. We then print the result of the equality check to standard output.

Dart Program

void main() {
  Future<int> future1 = Future<int>.value(42);
  Future<int> future2 = Future<int>.value(42);
  bool areEqual = (future1 == future2);
  print('Are future1 and future2 equal? $areEqual');
}

Output

Are future1 and future2 equal? false

Summary

In this Dart tutorial, we learned about operator == operator of Future: the syntax and few working examples with output and detailed explanation for each example.